package net.zigin.nhi.could.waste.service.impl;

import net.zigin.commons.util.*;
import net.zigin.nhi.could.waste.aop.LoginAspect;
import net.zigin.nhi.could.waste.dto.*;
import net.zigin.nhi.could.waste.service.WarnBaseService;
import net.zigin.nhi.could.waste.service.WarnTimeService;
import net.zigin.nhi.could.waste.service.WasteBaseRecordService;
import net.zigin.nhi.could.waste.vo.*;
import net.zigin.nhi.could.waste.constants.CommonConstants;
import net.zigin.nhi.could.waste.dao.*;
import net.zigin.nhi.could.waste.exception.EpiCloudException;
import net.zigin.nhi.could.waste.model.*;
import net.zigin.nhi.could.waste.util.EncryptDataUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import net.zigin.nhi.could.waste.service.WasteBaseService;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

/*#################################################################*
# 说明:以下代码通过哲勤代码生成工具自动生成    
# 工具:GeneratorCode
# 作者:mgw1986                                                  
# 生成时间:2021-9-13 21:14:42                                               
##################################################################*/


/**
 * WasteBase服务实现类
 *
 * @author mgw1986
 * @version V1.0
 * @ClassName: WasteBaseServiceImpl
 * @date 2021-9-13 21:14:42
 */
@Service
public class WasteBaseServiceImpl extends AbstractServiceImpl<WasteBase, String> implements WasteBaseService {
    @Autowired
    private WasteBaseMapper wasteBaseMapper;
    @Autowired
    private WasteBoxMapper wasteBoxMapper;
    @Autowired
    private SysUserHospitalMapper sysUserHospitalMapper;
    @Autowired
    private HospitalDepartMapper hospitalDepartMapper;
    @Autowired
    private HospitalBaseMapper hospitalBaseMapper;
    @Autowired
    private SysUserRevicerMapper sysUserRevicerMapper;
    @Autowired
    private WarnBaseService warnBaseService;
    @Autowired
    private HospitalPlaceMapper hospitalPlaceMapper;
    @Autowired
    private WasteBaseRecordService wasteBaseRecordService;
    @Autowired
    private WarnTimeService warnTimeService;
    @Autowired
    private WasteInMapper wasteInMapper;
    @Autowired
    private WasteInInfoMapper wasteInInfoMapper;
    @Autowired
    private WasteOutMapper wasteOutMapper;
    @Autowired
    private WasteOutInfoMapper wasteOutInfoMapper;
    @Autowired
    private WasteBoxRecordMapper wasteBoxRecordMapper;


    @Override
    public BaseMapper<WasteBase, String> getMapper() {
        return wasteBaseMapper;
    }

    @Override
    public String wasteCollect(WasteCollectDto wasteCollectDto) {
        if (wasteCollectDto.getWeight() == 0) {
            throw new EpiCloudException("收集重量为0，请重新读取重量！");
        }
        if (!StringUtil.isNullOrEmpty(wasteCollectDto.getRfid())) {
            // 判断rfid是否绑过医废
            Integer bindCount = wasteBaseMapper.getRfidBindCount(wasteCollectDto.getRfid());
            if (bindCount != null && bindCount > 0) {
                throw new EpiCloudException("RFID已经绑定过医废！");
            }
        }
        TokenInfoBo tokenInfo = LoginAspect.getTokenInfo();
        SysUserHospital collectUser = sysUserHospitalMapper.getByUserId(tokenInfo.getUserId());
        // todo 解析科室和移交人的二维码
        WasteBase wasteBase = new WasteBase(wasteCollectDto);
        SysUserHospital handUserStaff = getUserStaffByOrCode(wasteCollectDto.getHandUserQrCode());
        wasteBase.setHandUserStaffId(handUserStaff.getId());
        wasteBase.setHandUserStaffName(handUserStaff.getRealName());
        HospitalDepart hospitalDepart = getHospitalDepartByOrCode(wasteCollectDto.getDepartQrCode());
        wasteBase.setHospitalDepartId(hospitalDepart.getId());
        wasteBase.setHospitalDepartName(hospitalDepart.getName());
        wasteBase.setHospitalBaseId(hospitalDepart.getHospitalBaseId());
        wasteBase.setCollectUserStaffId(collectUser.getId());
        wasteBase.setCollectUserStaffName(collectUser.getRealName());
        HospitalBase hospitalBase = hospitalBaseMapper.selectByPrimaryKey(hospitalDepart.getHospitalBaseId());
        wasteBase.setHospitalBaseName(hospitalBase.getName());
        wasteBase.setCode(generateCode(hospitalBase));
        wasteBase.setIsDelete(0);
        wasteBaseMapper.insert(wasteBase);
        wasteBaseRecordService.generateRecord(wasteBase, wasteCollectDto.getRemark());
        warnTimeService.sendWarnMessage(wasteBase);
        return wasteBase.getId();
    }

    private String generateCode(HospitalBase hospitalBase) {
        StringBuffer stringBuffer = new StringBuffer();
        Date t = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyMMdd");
        stringBuffer.append("YF").append(hospitalBase.getNum()).append(df.format(t)).append(String.format("%04d", hospitalBase.getWasteNum()));
        HospitalBase temp = new HospitalBase();
        temp.setId(hospitalBase.getId());
        temp.setWasteNum(hospitalBase.getWasteNum() + 1);
        hospitalBaseMapper.updateByPrimaryKeySelective(temp);
        return stringBuffer.toString();
    }

    private String generateCKCode(HospitalBase hospitalBase) {
        StringBuffer stringBuffer = new StringBuffer();
        Date t = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyMMdd");
        stringBuffer.append("CK").append(hospitalBase.getNum()).append(df.format(t)).append(String.format("%04d", hospitalBase.getCkNum()));
        return stringBuffer.toString();
    }

    private String generateRKCode(HospitalBase hospitalBase) {
        StringBuffer stringBuffer = new StringBuffer();
        Date t = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyMMdd");
        stringBuffer.append("RK").append(hospitalBase.getNum()).append(df.format(t)).append(String.format("%04d", hospitalBase.getRkNum()));
        HospitalBase temp = new HospitalBase();
        temp.setId(hospitalBase.getId());
        temp.setRkNum(hospitalBase.getRkNum() + 1);
        hospitalBaseMapper.updateByPrimaryKeySelective(temp);
        return stringBuffer.toString();
    }

    @Override
    public void putSingleInStorage(WasteInPutStorageDto wasteInPutStorageDto) {
        TokenInfoBo tokenInfo = LoginAspect.getTokenInfo();
        AssertUtil.isNull(wasteInPutStorageDto.getWasteBaseId(), "");
        AssertUtil.isNull(wasteInPutStorageDto.getWeight(), "");
        WasteBase wasteBase = wasteBaseMapper.selectByPrimaryKey(wasteInPutStorageDto.getWasteBaseId());
        if (wasteBase.getStatus().equals("in_depot")) {
            return;
        }
        String hospitalBaseId = sysUserHospitalMapper.getHospitalBaseIdBySysUserId(tokenInfo.getUserId());
        HospitalBase hospitalBase = hospitalBaseMapper.selectByPrimaryKey(hospitalBaseId);
        String placeStaffUserId = sysUserHospitalMapper.getIdByUserId(tokenInfo.getUserId());
        wasteBase.setStatus("in_depot");
        HospitalPlaceVo hospitalPlaceVo = hospitalPlaceMapper.getInfoByUserStaffId(placeStaffUserId);
        if (hospitalPlaceVo != null) {
            wasteBase.setHospitalPlaceId(hospitalPlaceVo.getId());
            wasteBase.setHospitalPlaceName(hospitalPlaceVo.getName());
        }
        if (wasteInPutStorageDto.getWeight() != null) {
            // todo 生成预警
            String warn = warnBaseService.checkWeightRule(wasteBase.getStatus(), wasteBase.getWasteClassifyCode(), wasteBase.getWeight(), wasteInPutStorageDto.getWeight());
            warnBaseService.generateWarn(wasteBase, warn);
            //wasteBase.setWeight(wasteInPutStorageDto.getWeight());
        }
        wasteBase.setModifyTime(new Date());
        wasteBase.setModifyUser(tokenInfo.getLoginName());
        wasteBaseMapper.updateByPrimaryKeySelective(wasteBase);
        wasteBaseRecordService.generateRecord(wasteBase, wasteInPutStorageDto.getRemark(), wasteInPutStorageDto.getWeight());
        warnTimeService.sendWarnMessage(wasteBase);
        // todo 生成 waste_in waste_in_info
        WasteIn wasteIn = new WasteIn("single");
        wasteIn.setCode(generateRKCode(hospitalBase));
        wasteIn.setHospitalBaseId(hospitalBaseId);
        wasteInMapper.insert(wasteIn);
        WasteInInfo wasteInInfo = new WasteInInfo(StringUtil.get32UUID(), wasteIn.getId(), wasteBase.getId());
        wasteInInfoMapper.insert(wasteInInfo);
    }


    @Override
    public void putMultipleInStorage(WasteInPutStorageDto wasteInPutStorageDto) {
        TokenInfoBo tokenInfo = LoginAspect.getTokenInfo();
        AssertUtil.isNull(wasteInPutStorageDto.getWasteBaseIds(), "");
        // todo 只能批量入库同类型
        List<String> classify = wasteBaseMapper.getClassifyByIds(wasteInPutStorageDto.getWasteBaseIds());
        if (classify.size() > 1) {
            throw new EpiCloudException("只能批量入库同类型医废！请重新选择！");
        }
        // todo 重量差异过大拦截
        float allWeight = wasteBaseMapper.getWeightByIds(wasteInPutStorageDto.getWasteBaseIds());
        String rule = warnBaseService.checkWeightRule("in_depot", classify.get(0), allWeight, wasteInPutStorageDto.getWeight());
        if (!StringUtil.isNullOrEmpty(rule)) {
            throw new EpiCloudException("重量与收集时差异过大！请重新称重！");
        }
        String placeStaffUserId = sysUserHospitalMapper.getIdByUserId(tokenInfo.getUserId());
        HospitalPlaceVo hospitalPlaceVo = hospitalPlaceMapper.getInfoByUserStaffId(placeStaffUserId);
        String hospitalBaseId = sysUserHospitalMapper.getHospitalBaseIdBySysUserId(tokenInfo.getUserId());
        HospitalBase hospitalBase = hospitalBaseMapper.selectByPrimaryKey(hospitalBaseId);
        WasteIn wasteIn = new WasteIn("batch");
        wasteIn.setCode(generateRKCode(hospitalBase));
        wasteIn.setHospitalBaseId(hospitalBaseId);
        wasteInMapper.insert(wasteIn);
        wasteInPutStorageDto.getWasteBaseIds().forEach(wasteBaseId -> {
            WasteBase wasteBase = wasteBaseMapper.selectByPrimaryKey(wasteBaseId);
            if (wasteBase.getStatus().equals("in_depot")) {
                return;
            }
            wasteBase.setStatus("in_depot");
            if (hospitalPlaceVo != null) {
                wasteBase.setHospitalPlaceId(hospitalPlaceVo.getId());
                wasteBase.setHospitalPlaceName(hospitalPlaceVo.getName());
            }
            wasteBase.setModifyTime(new Date());
            wasteBase.setModifyUser(tokenInfo.getLoginName());
            wasteBaseMapper.updateByPrimaryKeySelective(wasteBase);
            wasteBaseRecordService.generateRecord(wasteBase, wasteInPutStorageDto.getRemark());
            warnTimeService.sendWarnMessage(wasteBase);
            WasteInInfo wasteInInfo = new WasteInInfo(StringUtil.get32UUID(), wasteIn.getId(), wasteBase.getId());
            wasteInInfoMapper.insert(wasteInInfo);
        });
    }

    @Override
    public void putBoxInStorage(WasteInPutStorageDto wasteInPutStorageDto) {
        TokenInfoBo tokenInfo = LoginAspect.getTokenInfo();
        AssertUtil.isNull(wasteInPutStorageDto.getWasteBoxId(), "");
        WasteBox wasteBox = wasteBoxMapper.selectByPrimaryKey(wasteInPutStorageDto.getWasteBoxId());
        // todo 只能箱袋入库同类型
        List<String> classify = wasteBaseMapper.getClassifyByBoxId(wasteInPutStorageDto.getWasteBoxId());
        if (classify.size() > 1) {
            throw new EpiCloudException("只能箱袋入库同类型医废！请重新绑定！");
        }
        // todo 重量差异过大拦截
        Float collectWeight = wasteBaseMapper.getWeightByBoxIdAndStatus(wasteInPutStorageDto.getWasteBoxId(), "do_collect");
        String rule = warnBaseService.checkWeightRule("in_depot", classify.get(0), collectWeight + wasteBox.getWeight(), wasteInPutStorageDto.getWeight());
        if (!StringUtil.isNullOrEmpty(rule)) {
            throw new EpiCloudException("重量与收集时差异过大！请重新称重！");
        }
        String placeStaffUserId = sysUserHospitalMapper.getIdByUserId(tokenInfo.getUserId());
        HospitalPlaceVo hospitalPlaceVo = hospitalPlaceMapper.getInfoByUserStaffId(placeStaffUserId);
        List<WasteBase> list = wasteBaseMapper.getListByBoxId(wasteInPutStorageDto.getWasteBoxId());
        String hospitalBaseId = sysUserHospitalMapper.getHospitalBaseIdBySysUserId(tokenInfo.getUserId());
        HospitalBase hospitalBase = hospitalBaseMapper.selectByPrimaryKey(hospitalBaseId);
        WasteBoxRecord wasteBoxRecord = new WasteBoxRecord(wasteBox.getId(), wasteInPutStorageDto.getWeight());
        wasteBoxRecordMapper.insert(wasteBoxRecord);
        WasteIn wasteIn = new WasteIn(wasteBoxRecord);
        wasteIn.setCode(generateRKCode(hospitalBase));
        wasteIn.setWasteBoxCode(wasteBox.getCode());
        wasteIn.setHospitalBaseId(hospitalBaseId);
        wasteInMapper.insert(wasteIn);
        list.forEach(wasteBase -> {
            if (wasteBase.getStatus().equals("in_depot")) {
                return;
            }
            wasteBase.setStatus("in_depot");
            if (hospitalPlaceVo != null) {
                wasteBase.setHospitalPlaceId(hospitalPlaceVo.getId());
                wasteBase.setHospitalPlaceName(hospitalPlaceVo.getName());
            }
            wasteBase.setWasteBoxRecordId(wasteBoxRecord.getId());
            wasteBase.setModifyTime(new Date());
            wasteBase.setModifyUser(tokenInfo.getLoginName());
            wasteBaseMapper.updateByPrimaryKeySelective(wasteBase);
            wasteBaseRecordService.generateRecord(wasteBase, wasteInPutStorageDto.getRemark());
            warnTimeService.sendWarnMessage(wasteBase);
            WasteInInfo wasteInInfo = new WasteInInfo(StringUtil.get32UUID(), wasteIn.getId(), wasteBase.getId());
            wasteInInfoMapper.insert(wasteInInfo);
        });
    }

    @Override
    public WasteBaseVo getSingleInStorageInfo(WasteInPutStorageDto wasteInPutStorageDto) {
        AssertUtil.isNull(wasteInPutStorageDto.getCollectUserQrCode(), "");
        AssertUtil.isNull(wasteInPutStorageDto.getWasteQrCode(), "");
        WasteBase wasteBase = getWasteBaseByQrCode(wasteInPutStorageDto.getWasteQrCode());
        SysUserHospital collectUserStaff = getUserStaffByOrCode(wasteInPutStorageDto.getCollectUserQrCode());
        if (!collectUserStaff.getId().equals(wasteBase.getCollectUserStaffId())) {
            throw new EpiCloudException("收集人信息错误！医废收集人：" + wasteBase.getCollectUserStaffName() + "当前收集人：" + collectUserStaff.getRealName());
        }
        return ReflectUtil.copyProperties(wasteBase, WasteBaseVo.class);
    }

    @Override
    public List<WasteBaseVo> getMultipleInStorageInfo(WasteInPutStorageDto wasteInPutStorageDto) {
        List<WasteBaseVo> result = new ArrayList<>();
        AssertUtil.isNull(wasteInPutStorageDto.getCollectUserQrCode(), "");
        AssertUtil.isNull(wasteInPutStorageDto.getWasteOrCodes(), "");
        SysUserHospital collectUserStaff = getUserStaffByOrCode(wasteInPutStorageDto.getCollectUserQrCode());
        wasteInPutStorageDto.getWasteOrCodes().forEach(wasteQrCode -> {
            WasteBase wasteBase = getWasteBaseByQrCode(wasteQrCode);
            if (!collectUserStaff.getId().equals(wasteBase.getCollectUserStaffId())) {
                throw new EpiCloudException("收集人信息错误！医废收集人：" + wasteBase.getCollectUserStaffName() + "当前收集人：" + collectUserStaff.getRealName());
            }
            result.add(ReflectUtil.copyProperties(wasteBase, WasteBaseVo.class));
        });
        return result;
    }

    @Override
    public Map<String, Object> getBoxInStorageInfo(WasteInPutStorageDto wasteInPutStorageDto) {
        Map<String, Object> result = new HashMap<>();
        List<WasteBaseVo> voList = new ArrayList<>();
        AssertUtil.isNull(wasteInPutStorageDto.getWasteBoxId(), "");
        AssertUtil.isNull(wasteInPutStorageDto.getCollectUserQrCode(), "");
        WasteBoxVo boxInfo = wasteBoxMapper.getInfoById(wasteInPutStorageDto.getWasteBoxId());
        // 完善箱的信息
        SysUserHospital collectUserStaff = getUserStaffByOrCode(wasteInPutStorageDto.getCollectUserQrCode());
        SysUserHospitalVo collectUser = new SysUserHospitalVo();
        collectUser.setId(collectUserStaff.getId());
        collectUser.setRealName(collectUserStaff.getRealName());
        List<WasteBase> list = wasteBaseMapper.getListByBoxIdAndStatus(wasteInPutStorageDto.getWasteBoxId(), "do_collect");
        boxInfo.setCollectUserStaffName(collectUserStaff.getRealName());
        AtomicReference<Float> allWeight = new AtomicReference<>((float) 0);
        list.forEach(wasteBase -> {
            if (!collectUserStaff.getId().equals(wasteBase.getCollectUserStaffId())) {
                throw new EpiCloudException("收集人信息错误！医废收集人：" + wasteBase.getCollectUserStaffName() + "当前收集人：" + collectUserStaff.getRealName());
            }
            allWeight.updateAndGet(v -> (float) (v + wasteBase.getWeight()));
            voList.add(ReflectUtil.copyProperties(wasteBase, WasteBaseVo.class));
        });
        boxInfo.setCollectWeight(allWeight.get() + boxInfo.getWeight());
        result.put("wasteBaseList", voList);
        result.put("wasteBox", boxInfo);
        result.put("collectUser", collectUser);
        return result;
    }

    @Override
    public String bindBagWithBox(WasteInPutStorageDto wasteInPutStorageDto) {
        AssertUtil.isNull(wasteInPutStorageDto.getWasteBoxQrCode(), "");
        AssertUtil.isNull(wasteInPutStorageDto.getWasteBaseIds(), "");
        WasteBox wasteBox = getWasteBoxByQrCode(wasteInPutStorageDto.getWasteBoxQrCode());
        //AtomicReference<Float> allWeight = new AtomicReference<>((float) 0);
        wasteInPutStorageDto.getWasteBaseIds().forEach(wasteBaseId -> {
            WasteBase wasteBase = wasteBaseMapper.selectByPrimaryKey(wasteBaseId);
            wasteBase.setWasteBoxId(wasteBox.getId());
            wasteBase.setWasteBoxCode(wasteBox.getCode());
            //allWeight.updateAndGet(v -> (float) (v + wasteBase.getWeight()));
            wasteBaseMapper.updateByPrimaryKeySelective(wasteBase);
        });
        //wasteBox.setWeight(allWeight.get());
        wasteBoxMapper.updateByPrimaryKeySelective(wasteBox);
        return wasteBox.getId();
    }

    @Override
    public void removeBindBagWithBox(WasteInPutStorageDto wasteInPutStorageDto) {
        // todo
        AssertUtil.isNull(wasteInPutStorageDto.getWasteBoxId(), "");
        AssertUtil.isNull(wasteInPutStorageDto.getWasteBaseIds(), "");
        WasteBox wasteBox = wasteBoxMapper.selectByPrimaryKey(wasteInPutStorageDto.getWasteBoxId());
        if (wasteInPutStorageDto.getWasteBaseIds().isEmpty()) {
            // 解除所有
            wasteBaseMapper.removeAllBindBagWithBox(wasteBox.getId());
        } else {
            wasteBaseMapper.removeSomeBindBagWithBox(wasteBox.getId(), wasteInPutStorageDto.getWasteBaseIds());
        }
    }

    @Override
    public WasteBaseVo getInfoByQrCode(String qrCode) {
        WasteBase wasteBase = getWasteBaseByQrCode(qrCode);
        return ReflectUtil.copyProperties(wasteBase, WasteBaseVo.class);
    }

    @Override
    public List<WasteBaseVo> getListByBoxId(String wasteBoxId) {
        List<WasteBase> list = wasteBaseMapper.getListByBoxId(wasteBoxId);
        if (list.isEmpty()) {
            return new ArrayList<>();
        }
        return ReflectUtil.copyProperties(list, WasteBaseVo.class);
    }

    @Override
    public Map<String, Object> getListByBoxQrCode(String wasteBoxQrCode) {
        Map<String, Object> result = new HashMap<>();
        WasteBox wasteBox = getWasteBoxByQrCode(wasteBoxQrCode);
        WasteBoxVo wasteBoxVo = ReflectUtil.copyProperties(wasteBox, WasteBoxVo.class);
        List<WasteBaseVo> wasteBaseVos = this.getListByBoxId(wasteBox.getId());
        AtomicReference<Float> weight = new AtomicReference<>(0F);
        wasteBaseVos.forEach(wasteBaseVo -> {
            weight.updateAndGet(v -> v + wasteBaseVo.getWeight());
        });
        // 通过医废的状态设置箱的状态 如果未绑定医废 则状态也为收集
        if (wasteBaseVos.size() > 0) {
            wasteBoxVo.setWasteBoxRecordId(wasteBaseVos.get(0).getWasteBoxRecordId());
            wasteBoxVo.setStatus(wasteBaseVos.get(0).getStatus());
        } else {
            wasteBoxVo.setStatus("do_collect");
        }
        wasteBoxVo.setCollectWeight(weight.get() + wasteBoxVo.getWeight());
        result.put("wasteBaseList", wasteBaseVos);
        result.put("wasteBox", wasteBoxVo);
        return result;
    }

    @Override
    public Map<String, Object> getPendingInStorageList(WasteInPutStorageDto wasteInPutStorageDto) {
        SysUserHospital collectUserStaff = getUserStaffByOrCode(wasteInPutStorageDto.getCollectUserQrCode());
        Map<String, Object> paramMap = getPendingInStorageParam(wasteInPutStorageDto, collectUserStaff);
        List<WasteBase> list = new ArrayList<>();
        wasteInPutStorageDto.setIsPage(false);
        if (wasteInPutStorageDto.getIsPage()) {
            list = wasteBaseMapper.selectListByPage(paramMap);
        } else {
            list = wasteBaseMapper.selectListByCondition(paramMap);
        }
        List<WasteBaseVo> wasteBaseVos;
        if (list.isEmpty()) {
            wasteBaseVos = new ArrayList<>();
        } else {
            wasteBaseVos = ReflectUtil.copyProperties(list, WasteBaseVo.class);
        }
        SysUserHospitalVo collectUser = new SysUserHospitalVo();
        collectUser.setId(collectUserStaff.getId());
        collectUser.setRealName(collectUserStaff.getRealName());
        Map<String, Object> result = new HashMap<>();
        result.put("wasteBases", wasteBaseVos);
        result.put("collectUser", collectUser);
        return result;
    }

    @Override
    public List<WasteBaseVo> getPendingOutStorageList() {
        TokenInfoBo tokenInfo = LoginAspect.getTokenInfo();
        String hospitalBaseId = sysUserHospitalMapper.getHospitalBaseIdBySysUserId(tokenInfo.getUserId());
        List<WasteBase> list = wasteBaseMapper.getPendingOutStorageList(hospitalBaseId);
        if (list.isEmpty()) {
            return new ArrayList<>();
        }
        return ReflectUtil.copyProperties(list, WasteBaseVo.class);
    }

    @Override
    public Integer getPendingInStorageListCount(WasteInPutStorageDto wasteInPutStorageDto) {
        SysUserHospital collectUserStaff = getUserStaffByOrCode(wasteInPutStorageDto.getCollectUserQrCode());
        Map<String, Object> paramMap = getPendingInStorageParam(wasteInPutStorageDto, collectUserStaff);
        return wasteBaseMapper.selectCount(paramMap);
    }

    @Override
    public void putSingleOutStorage(WasteOutPutStorageDto wasteOutPutStorageDto) {
        TokenInfoBo tokenInfo = LoginAspect.getTokenInfo();
        AssertUtil.isNull(wasteOutPutStorageDto.getWasteBaseId(), "");
        AssertUtil.isNull(wasteOutPutStorageDto.getWeight(), "");
        WasteBase wasteBase = wasteBaseMapper.selectByPrimaryKey(wasteOutPutStorageDto.getWasteBaseId());
        wasteBase.setStatus("out_depot");
        if (wasteOutPutStorageDto.getWeight() != null) {
            // todo 生成预警
            //wasteBase.setWeight(wasteOutPutStorageDto.getWeight());
        }
        wasteBase.setModifyTime(new Date());
        wasteBase.setModifyUser(tokenInfo.getLoginName());
        wasteBaseMapper.updateByPrimaryKeySelective(wasteBase);
    }

    @Override
    public Map<String, Object> getPrintMessage(WasteOutPutStorageDto wasteOutPutStorageDto) {
        // todo 传箱ID 箱入库
        //      ids 批量入库 单个入库
        TokenInfoBo tokenInfo = LoginAspect.getTokenInfo();
        String hospitalBaseId = sysUserHospitalMapper.getHospitalBaseIdBySysUserId(tokenInfo.getUserId());
        HospitalBase hospitalBase = hospitalBaseMapper.selectByPrimaryKey(hospitalBaseId);
        String ckCode = generateCKCode(hospitalBase);
        List<WasteBaseVo> list = wasteBaseMapper.getPrintMessage(wasteOutPutStorageDto);
        Map<String, Object> result = new HashMap<>();
        result.put("list", list);
        result.put("ckCode", ckCode);
        return result;
    }

    @Override
    public void printMessage(WasteOutPutStorageDto wasteOutPutStorageDto) {
        TokenInfoBo tokenInfo = LoginAspect.getTokenInfo();
        String hospitalBaseId = sysUserHospitalMapper.getHospitalBaseIdBySysUserId(tokenInfo.getUserId());
        HospitalBase hospitalBase = hospitalBaseMapper.selectByPrimaryKey(hospitalBaseId);
        String ckCode = wasteOutPutStorageDto.getCkCode();
        WasteOut wasteOut = new WasteOut(ckCode);
        SysUserRevicer sysUserRevicer = sysUserRevicerMapper.selectByPrimaryKey(wasteOutPutStorageDto.getRevicerId());
        wasteOut.setUserRevicerId(sysUserRevicer.getId());
        wasteOut.setUserRevicerName(sysUserRevicer.getRealName());
        wasteOut.setHospitalBaseId(hospitalBaseId);
        // 批量
        if (wasteOutPutStorageDto.getWasteBaseIds() != null && wasteOutPutStorageDto.getWeight() != null) {
            wasteOut.setWeight(wasteOutPutStorageDto.getWeight());
            // todo 超重检测
            Float collectWeight = wasteBaseMapper.getWeightByIds(wasteOutPutStorageDto.getWasteBaseIds());
            String rule = warnBaseService.checkWeightRule("out_depot", wasteOutPutStorageDto.getWasteClassifyCode(), collectWeight, wasteOutPutStorageDto.getWeight());
            if (!StringUtil.isNullOrEmpty(rule)) {
                throw new EpiCloudException("重量与收集时差异过大！请重新称重！");
            }
            wasteOut.setType("batch");
            wasteOutPutStorageDto.getWasteBaseIds().forEach(wasteBaseId -> {
                WasteBase wasteBase = wasteBaseMapper.selectByPrimaryKey(wasteBaseId);
                WasteOutInfo wasteOutInfo = new WasteOutInfo(StringUtil.get32UUID(), wasteOut.getId(), wasteBase.getId());
                wasteOutInfoMapper.insert(wasteOutInfo);
                wasteBase.setStatus("out_depot");
                wasteBase.setUserRevicerId(sysUserRevicer.getId());
                wasteBase.setUserRevicerName(sysUserRevicer.getRealName());
                wasteBase.setModifyTime(new Date());
                wasteBase.setModifyUser(tokenInfo.getLoginName());
                wasteBaseMapper.updateByPrimaryKeySelective(wasteBase);
                wasteBaseRecordService.generateRecord(wasteBase, wasteOutPutStorageDto.getRemark());
            });
        }

        // 医废扫码
        if (wasteOutPutStorageDto.getWasteBaseDtos() != null) {
            wasteOut.setType("single");
            wasteOutPutStorageDto.getWasteBaseDtos().forEach(wasteBaseDto -> {
                WasteBase wasteBase = wasteBaseMapper.selectByPrimaryKey(wasteBaseDto.getId());
                if (wasteBase.getStatus().equals("in_depot")) { // 前台可能存在重复扫描的情况
                    WasteOutInfo wasteOutInfo = new WasteOutInfo(StringUtil.get32UUID(), wasteOut.getId(), wasteBase.getId());
                    wasteOutInfoMapper.insert(wasteOutInfo);
                    wasteBase.setStatus("out_depot");
                    wasteBase.setUserRevicerId(sysUserRevicer.getId());
                    wasteBase.setUserRevicerName(sysUserRevicer.getRealName());
                    wasteBase.setModifyTime(new Date());
                    wasteBase.setModifyUser(tokenInfo.getLoginName());
                    if (wasteBaseDto.getWeight() != 0) {
                        String warn = warnBaseService.checkWeightRule(wasteBase.getStatus(), wasteBase.getWasteClassifyCode(), wasteBase.getWeight(), wasteBaseDto.getWeight());
                        warnBaseService.generateWarn(wasteBase, warn);
                    }
                    wasteBaseMapper.updateByPrimaryKeySelective(wasteBase);
                    wasteBaseRecordService.generateRecord(wasteBase, wasteOutPutStorageDto.getRemark(), wasteBaseDto.getWeight());
                }
            });
            Float all = wasteOutPutStorageDto.getWasteBaseDtos().stream().map(WasteBaseDto::getWeight).reduce(Float::sum).orElse(0f);
            wasteOut.setWeight(all);
        }
        // 箱
        WasteBoxDto wasteBoxDto = wasteOutPutStorageDto.getWasteBoxDto();
        if (wasteBoxDto != null) {
            wasteOut.setWeight(wasteBoxDto.getWeight());
            wasteOut.setType("box");
            WasteBox wasteBox = wasteBoxMapper.selectByPrimaryKey(wasteBoxDto.getId());
            wasteOut.setWasteBoxCode(wasteBox.getCode());
            wasteOut.setWasteBoxId(wasteBox.getId());
            wasteOut.setWasteBoxRecordId(wasteBoxDto.getWasteBoxRecordId());
            WasteBoxRecord wasteBoxRecord = wasteBoxRecordMapper.selectByPrimaryKey(wasteBoxDto.getWasteBoxRecordId());
            wasteBoxRecord.setStatus("out_depot");
            wasteBoxRecord.setOutTime(new Date());
            wasteBoxRecord.setOutWeight(wasteBoxDto.getWeight());
            wasteBoxRecordMapper.updateByPrimaryKeySelective(wasteBoxRecord);
            // 箱出库重量预警
            Float collectWeight = wasteBaseMapper.getWeightByBoxIdAndStatus(wasteBoxDto.getId(), "in_depot");
            String warn = warnBaseService.checkWeightRule("out_depot", wasteBoxDto.getWasteClassifyCode(), collectWeight + wasteBox.getWeight(), wasteBoxDto.getWeight());
            warnBaseService.generateWarn(wasteBox, wasteBoxRecord, warn, wasteBox.getCode());
            List<WasteBase> list = wasteBaseMapper.getListByBoxId(wasteBoxDto.getId());
            list.forEach(wasteBase -> {
                WasteOutInfo wasteOutInfo = new WasteOutInfo(StringUtil.get32UUID(), wasteOut.getId(), wasteBase.getId());
                wasteOutInfoMapper.insert(wasteOutInfo);
                wasteBase.setStatus("out_depot");
                wasteBase.setUserRevicerId(sysUserRevicer.getId());
                wasteBase.setUserRevicerName(sysUserRevicer.getRealName());
                wasteBase.setModifyTime(new Date());
                wasteBase.setModifyUser(tokenInfo.getLoginName());
                wasteBaseMapper.updateByPrimaryKeySelective(wasteBase);
                wasteBaseRecordService.generateRecord(wasteBase, wasteOutPutStorageDto.getRemark());
            });
            // 清除绑定状态
            wasteBaseMapper.removeBoxIdAfterOutDepot(wasteBox.getId());
        }
        wasteOutMapper.insert(wasteOut);
        HospitalBase temp = new HospitalBase();
        temp.setId(hospitalBase.getId());
        temp.setCkNum(hospitalBase.getCkNum() + 1);
        hospitalBaseMapper.updateByPrimaryKeySelective(temp);
    }

    @Override
    public void putBoxOutStorage(WasteOutPutStorageDto wasteOutPutStorageDto) {
        TokenInfoBo tokenInfo = LoginAspect.getTokenInfo();
        AssertUtil.isNull(wasteOutPutStorageDto.getWasteBoxId(), "");
        AssertUtil.isNull(wasteOutPutStorageDto.getWeight(), "");
        WasteBox wasteBox = wasteBoxMapper.selectByPrimaryKey(wasteOutPutStorageDto.getWasteBoxId());
        if (wasteBox.getWeight() - wasteOutPutStorageDto.getWeight() > 0) {
            // todo 判断预警规则
        }
        List<WasteBase> list = wasteBaseMapper.getListByBoxId(wasteOutPutStorageDto.getWasteBoxId());
        list.forEach(wasteBase -> {
            wasteBase.setStatus("out_depot");
            if (wasteOutPutStorageDto.getWeight() != null) {
                // todo 生成预警
                //wasteBase.setWeight(wasteOutPutStorageDto.getWeight());
            }
            wasteBase.setModifyTime(new Date());
            wasteBase.setModifyUser(tokenInfo.getLoginName());
            wasteBaseMapper.updateByPrimaryKeySelective(wasteBase);
        });
    }

    private Map<String, Object> getPendingInStorageParam(WasteInPutStorageDto wasteInPutStorageDto, SysUserHospital collectUserStaff) {
        Map<String, Object> paramMap = ParamsMapUtil.getInstance()
                .addParam("bind", "1")
                .addParam("status", "do_collect")
                .addParam("collectUserStaffId", collectUserStaff.getId())
                .addParam("hospitalBaseId", collectUserStaff.getHospitalBaseId())
                .addParam("pageIndex", wasteInPutStorageDto.getPageIndex())
                .addParam("pageSize", wasteInPutStorageDto.getPageSize());
        return paramMap;
    }

    @Override
    public String generateQrCode(String id) {
        WasteBase wasteBase = wasteBaseMapper.selectByPrimaryKey(id);
        if (wasteBase == null) {
            throw new EpiCloudException("医废不存在");
        }
        return EncryptDataUtil.encryptData("wasteBase", wasteBase.getId());
    }

    @Override
    public String checkWarnWeight(WasteBaseDto wasteBaseDto) {
        if (!StringUtil.isNullOrEmpty(wasteBaseDto.getId())) {
            WasteBase wasteBase = wasteBaseMapper.selectByPrimaryKey(wasteBaseDto.getId());
            return warnBaseService.checkWeightRule(wasteBase.getStatus(), wasteBase.getWasteClassifyCode(), wasteBase.getWeight(), wasteBaseDto.getWeight());
        } else if (!StringUtil.isNullOrEmpty(wasteBaseDto.getWasteBoxId())) {
            WasteBox wasteBox = wasteBoxMapper.selectByPrimaryKey(wasteBaseDto.getWasteBoxId());
            // todo 不确定箱如何预警
            Float collectWeight = wasteBaseMapper.getWeightByBoxIdAndStatus(wasteBaseDto.getWasteBoxId(), "in_depot");
            return warnBaseService.checkWeightRule("out_depot", wasteBaseDto.getWasteClassifyCode(), collectWeight + wasteBox.getWeight(), wasteBaseDto.getWeight());
        } else if (wasteBaseDto.getIds() != null && !wasteBaseDto.getIds().isEmpty()) {
            Float collectWeight = wasteBaseMapper.getWeightByIds(wasteBaseDto.getIds());
            return warnBaseService.checkWeightRule("out_depot", wasteBaseDto.getWasteClassifyCode(), collectWeight, wasteBaseDto.getWeight());
        }
        return "";
    }

    @Override
    public List<WasteBaseVo> getList(WasteBaseDto wasteBaseDto) {
        // 时间 类型 状态 科室 医院
        Map<String, Object> paramMap = getWasteBaseParam(wasteBaseDto);
        return wasteBaseMapper.getPageListByCondition(paramMap);
    }

    @Override
    public List<WasteBaseVo> getCurrentCollectList() {
        TokenInfoBo tokenInfo = LoginAspect.getTokenInfo();
        String collectUserStaffId = sysUserHospitalMapper.getIdByUserId(tokenInfo.getUserId());
        List<WasteBase> list = wasteBaseMapper.getCurrentCollectList(collectUserStaffId);
        if (list.isEmpty()) {
            return new ArrayList<>();
        }
        List<WasteBaseVo> wasteBaseVos = ReflectUtil.copyProperties(list, WasteBaseVo.class);
        wasteBaseVos.forEach(wasteBaseVo -> {
            wasteBaseVo.setQrCode(this.generateQrCode(wasteBaseVo.getId()));
        });
        return wasteBaseVos;
    }

    @Override
    public Map<String, Object> getListByCodes(List<String> codes) {
        List<WasteBase> wasteBases = wasteBaseMapper.getListByCodes(codes);
        Optional<Float> optional = wasteBases.stream().map(WasteBase::getWeight).reduce(Float::sum);
        Map<String, Object> result = new HashMap<>();
        result.put("wasteBases", ReflectUtil.copyProperties(wasteBases, WasteBaseVo.class));
        result.put("weight", optional.isPresent() ? optional.get() : 0);
        return result;
    }

    @Override
    public Map<String, Object> getListByRFID(List<String> rfids) {
        List<WasteBase> wasteBases = wasteBaseMapper.getListByRFID(rfids);
        Optional<Float> optional = wasteBases.stream().map(WasteBase::getWeight).reduce(Float::sum);
        Map<String, Object> result = new HashMap<>();
        result.put("wasteBases", ReflectUtil.copyProperties(wasteBases, WasteBaseVo.class));
        result.put("weight", optional.isPresent() ? optional.get() : 0);
        return result;
    }

    @Override
    public Integer getCount(WasteBaseDto wasteBaseDto) {
        Map<String, Object> paramMap = getWasteBaseParam(wasteBaseDto);
        return wasteBaseMapper.getPageCountByCondition(paramMap);
    }

    @Override
    public HospitalDepartVo getDepartByQrCode(QrCodeDto qrCodeDto) {
        HospitalDepart depart = getHospitalDepartByOrCode(qrCodeDto.getContent());
        return ReflectUtil.copyProperties(depart, HospitalDepartVo.class);
    }

    @Override
    public List<HospitalDepartVo> getDepartByHospitalBaseId() {
        TokenInfoBo tokenInfo = LoginAspect.getTokenInfo();
        String hospitalBaseId = sysUserHospitalMapper.getHospitalBaseIdBySysUserId(tokenInfo.getUserId());
        List<HospitalDepart> list = hospitalDepartMapper.getListByHospitalBaseId(hospitalBaseId, "");
        List<HospitalDepartVo> hospitalDepartVos = ReflectUtil.copyProperties(list, HospitalDepartVo.class);
        List<HospitalDepartVo> parents = hospitalDepartVos.stream().filter(hospitalDepartVo -> StringUtil.isNullOrEmpty(hospitalDepartVo.getParentId())).collect(Collectors.toList());
        hospitalDepartVos.removeAll(parents);
        parents.forEach(hospitalDepartVo -> fillTree(hospitalDepartVos, hospitalDepartVo));
        return parents;
    }

    // 递归 将科室列表封装成树
    private void fillTree(List<HospitalDepartVo> list, HospitalDepartVo parent) {
        List<HospitalDepartVo> children = list.stream().filter(hospitalDepartVo -> hospitalDepartVo.getParentId().equals(parent.getId())).collect(Collectors.toList());
        parent.setChildren(children);
        list.removeAll(children);
        children.forEach(hospitalDepartVo -> fillTree(list, hospitalDepartVo));
    }

    @Override
    public List<HospitalDepartVo> getDepartByParentId(String parentId) {
        TokenInfoBo tokenInfo = LoginAspect.getTokenInfo();
        String hospitalBaseId = sysUserHospitalMapper.getHospitalBaseIdBySysUserId(tokenInfo.getUserId());
        List<HospitalDepart> list = hospitalDepartMapper.getListByHospitalBaseId(hospitalBaseId, parentId);
        if (list.isEmpty()) {
            return new ArrayList<>();
        }
        return ReflectUtil.copyProperties(list, HospitalDepartVo.class);
    }

    @Override
    public Map<String, Object> getListWithWeightByIds(List<String> ids) {
        List<WasteBase> wasteBases = wasteBaseMapper.getListByIds(ids);
        Optional<Float> optional = wasteBases.stream().map(WasteBase::getWeight).reduce(Float::sum);
        Map<String, Object> result = new HashMap<>();
        result.put("wasteBases", ReflectUtil.copyProperties(wasteBases, WasteBaseVo.class));
        result.put("weight", optional.isPresent() ? optional.get() : 0);
        return result;
    }

    @Override
    public Map<String, Object> warnInfoByBoxRecordId(String boxRecordId) {
        List<WasteBase> wasteBases = wasteBaseMapper.listByWasteBoxRecordId(boxRecordId);
        Float collectWeight = wasteBases.stream().map(WasteBase::getWeight).reduce(Float::sum).orElse(0f);
        WasteBoxRecord wasteBoxRecord = wasteBoxRecordMapper.selectByPrimaryKey(boxRecordId);
        WasteBox wasteBox = wasteBoxMapper.selectByPrimaryKey(wasteBoxRecord.getWasteBoxId());
        Map<String, Object> result = new HashMap<>();
        result.put("wasteBox", ReflectUtil.copyProperties(wasteBox, WasteBoxVo.class));
        result.put("wasteBoxRecord", ReflectUtil.copyProperties(wasteBoxRecord, WasteBoxRecordVo.class));
        result.put("collectWeight", NumberUtil.scaleFloat(collectWeight + wasteBox.getWeight(), 2));
        if (result.isEmpty()) {
            result.put("wasteBases", new ArrayList<>());
        } else {
            result.put("wasteBases", ReflectUtil.copyProperties(wasteBases, WasteBaseVo.class));
        }
        return result;
    }

    @Override
    public List<WasteOutVo> getWasteOutList(WasteBaseDto wasteBaseDto) {
        Map<String, Object> paramMap = getWasteOutParam(wasteBaseDto);
        List<WasteOut> wasteOuts = wasteOutMapper.selectListByPage(paramMap);
        if (wasteOuts.isEmpty()) {
            return new ArrayList<>();
        }
        List<WasteOutVo> wasteOutVos = ReflectUtil.copyProperties(wasteOuts, WasteOutVo.class);
        wasteOutVos.forEach(wasteOutVo -> {
            SysUserRevicer sysUserRevicer = sysUserRevicerMapper.selectByPrimaryKey(wasteOutVo.getUserRevicerId());
            wasteOutVo.setSysUserRevicerVo(ReflectUtil.copyProperties(sysUserRevicer, SysUserRevicerVo.class));
        });
        return wasteOutVos;
    }

    @Override
    public Integer getWasteOutCount(WasteBaseDto wasteBaseDto) {
        Map<String, Object> paramMap = getWasteOutParam(wasteBaseDto);
        return wasteOutMapper.selectCount(paramMap);
    }

    @Override
    public List<WasteBaseVo> getWasteOutInfo(String wasteOutId) {
        return wasteBaseMapper.getWasteOutInfo(wasteOutId);
    }

    private Map<String, Object> getWasteOutParam(WasteBaseDto wasteBaseDto) {
        TokenInfoBo tokenInfo = LoginAspect.getTokenInfo();
        String hospitalBaseId = sysUserHospitalMapper.getHospitalBaseIdBySysUserId(tokenInfo.getUserId());
        return ParamsMapUtil.getInstance()
                .addParam("hospitalBaseId", hospitalBaseId)
                .addParam("pageSize", wasteBaseDto.getPageSize())
                .addParam("pageIndex", wasteBaseDto.getPageIndex());
    }

    private Map<String, Object> getWasteBaseParam(WasteBaseDto wasteBaseDto) {
        if (!StringUtil.isNullOrEmpty(wasteBaseDto.getCollectTimeStart()) && !StringUtil.isNullOrEmpty(wasteBaseDto.getCollectTimeEnd())) {
            if (wasteBaseDto.getCollectTimeStart().equals(wasteBaseDto.getCollectTimeEnd())) {
                wasteBaseDto.setCollectTimeEnd(wasteBaseDto.getCollectTimeStart().trim() + " 23:59:59");
            }
        }
        TokenInfoBo tokenInfo = LoginAspect.getTokenInfo();
        String hospitalBaseId = sysUserHospitalMapper.getHospitalBaseIdBySysUserId(tokenInfo.getUserId());
        return ParamsMapUtil.getInstance()
                .addParam("hospitalBaseId", hospitalBaseId)
                .addParam("hospitalDepartId", wasteBaseDto.getHospitalDepartId())
                .addParam("status", wasteBaseDto.getStatus())
                .addParam("ckCode", wasteBaseDto.getCkCode())
                .addParam("wasteClassifyCode", wasteBaseDto.getWasteClassifyCode())
                .addParam("collectTimeStart", wasteBaseDto.getCollectTimeStart())
                .addParam("collectTimeEnd", wasteBaseDto.getCollectTimeEnd())
                .addParam("pageIndex", wasteBaseDto.getPageIndex())
                .addParam("pageSize", wasteBaseDto.getPageSize());
    }

    private SysUserHospital getUserStaffByOrCode(String qrCode) {
        // sysUserId
        EncryptDataUtil.EncryptData handUserQrCode = EncryptDataUtil.decryptData(qrCode);
        if (handUserQrCode.getType().equals(CommonConstants.QRCODE_USER_STAFF)) {
            String sysUserId = handUserQrCode.getData();
            SysUserHospital sysUserHospital = sysUserHospitalMapper.getByUserId(sysUserId);
            AssertUtil.isNull(sysUserHospital, "员工不存在，请重新打印二维码！");
            return sysUserHospital;
        } else {
            throw new EpiCloudException("员工二维码错误！");
        }
    }

    private HospitalDepart getHospitalDepartByOrCode(String qrCode) {
        // hospitalDepartId
        EncryptDataUtil.EncryptData handUserQrCode = EncryptDataUtil.decryptData(qrCode);
        if (handUserQrCode.getType().equals(CommonConstants.QRCODE_HOSPITAL_DEPART)) {
            String hospitalDepartId = handUserQrCode.getData();
            HospitalDepart hospitalDepart = hospitalDepartMapper.selectByPrimaryKey(hospitalDepartId);
            AssertUtil.isNull(hospitalDepart, "科室不存在，请重新打印二维码！");
            return hospitalDepart;
        } else {
            throw new EpiCloudException("科室二维码错误！");
        }
    }

    private WasteBase getWasteBaseByQrCode(String qrCode) {
        EncryptDataUtil.EncryptData handUserQrCode = EncryptDataUtil.decryptData(qrCode);
        // todo 这里存在医废是否需要不同阶段不同二维码？？？
        if (handUserQrCode.getType() != null) {
            String wasteBaseId = handUserQrCode.getData();
            WasteBase wasteBase = wasteBaseMapper.selectByPrimaryKey(wasteBaseId);
            AssertUtil.isNull(wasteBase, "医废不存在，请重新打印二维码！");
            return wasteBase;
        } else {
            throw new EpiCloudException("医废二维码错误！");
        }
    }

    private WasteBox getWasteBoxByQrCode(String qrCode) {
        EncryptDataUtil.EncryptData handUserQrCode = EncryptDataUtil.decryptData(qrCode);
        if (handUserQrCode.getType().equals(CommonConstants.QRCODE_WASTE_BOX)) {
            String wasteBaseId = handUserQrCode.getData();
            WasteBox wasteBox = wasteBoxMapper.selectByPrimaryKey(wasteBaseId);
            AssertUtil.isNull(wasteBox, "医废箱不存在，请重新打印二维码！");
            return wasteBox;
        } else {
            throw new EpiCloudException("医废箱二维码错误！");
        }
    }
}